#include <stdio.h>
#include <malloc.h>

int maxArr(int *,unsigned);
int main(void){
	unsigned num_count;
	scanf("%u",&num_count);
	int *arr=malloc(sizeof(int)*num_count);
	for(int i=0;i<num_count;i++){
		scanf("%d",&arr[i]);
	}
	printf("%d\n",maxArr(arr,num_count));
	return 0;
}


int maxArr(int *arr,unsigned count){
	int max=0;
	int group_v=0;
	for(int i=0;i<count;i++){
		if(group_v < 0)
			group_v=0;
		group_v+=arr[i];
		if( group_v > max )
			max=group_v;
		/*
		group_v+=arr[i];
		if(group_v>max)
			max=group_v;
		if(group_v<0)
			group_v=0;
		*/
	}
	return max;
}
